﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
using System.Data.OleDb;
using System.Xml;
using System.Diagnostics;

namespace ExpenseIt
{
    /// <summary>
    /// Interaction logic for ExpenseReportPage.xaml
    /// </summary>
    public partial class offlineModePage : Page
    {
        public offlineModePage()
        {
            string sSource;/*start of event logging*/
            string sLog;
            string sEvent;
            sSource = "Application";
            sLog = "Application";
            sEvent = "Entring offline.xaml";
            if (!EventLog.SourceExists(sSource))
                EventLog.CreateEventSource(sSource, sLog);
            EventLog.WriteEntry(sSource, sEvent);
            EventLog.WriteEntry(sSource, sEvent,
                EventLogEntryType.Warning, 234);/*end of event logging*/
            
            
            InitializeComponent();
            
            
            var pathOfExe = System.AppDomain.CurrentDomain.BaseDirectory;/* start of connecting to database and filling the datagrid*/
            var relativeToExe=pathOfExe+"test.mdb";
            string strAccessConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " + relativeToExe;
            string strAccessSelect = "SELECT * FROM Clients";
            DataSet myDataSet = new DataSet();
            OleDbConnection myAccessConn = null;
            try
            {
                myAccessConn = new OleDbConnection(strAccessConn);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: Failed to create a database connection. \n{0}", ex.Message);
                return;
            }
            try
            {
                OleDbCommand myAccessCommand = new OleDbCommand(strAccessSelect, myAccessConn);
                OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(myAccessCommand);
                myAccessConn.Open();
                myDataAdapter.Fill(myDataSet, "Clients");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: Failed to retrieve the required data from the DataBase.\n{0}", ex.Message);
                return;
            }
            finally
            {
                myAccessConn.Close();
            }
            DataTableCollection dta = myDataSet.Tables;
            foreach (DataTable dt in dta)
            {
                Console.WriteLine("Found data table {0}", dt.TableName);
            }
            Console.WriteLine("{0} tables in data set", myDataSet.Tables.Count);
            Console.WriteLine("{0} tables in data set", dta.Count);
            Console.WriteLine("{0} rows in Categories table", myDataSet.Tables["Clients"].Rows.Count);
            Console.WriteLine("{0} columns in Categories table", myDataSet.Tables["Clients"].Columns.Count);
            DataColumnCollection drc = myDataSet.Tables["Clients"].Columns;
            int i = 0;
            foreach (DataColumn dc in drc)
            {
                Console.WriteLine("Column name[{0}] is {1}, of type {2}", i++, dc.ColumnName, dc.DataType);
            }
            DataRowCollection dra = myDataSet.Tables["Clients"].Rows;
            // LibraryView.DataContext = dra;
            // LibraryView.Items.Refresh();
            Image image = new Image();
            image.Source = new BitmapImage(new Uri(@"D:\\blue.png"));
            LibraryView.ItemsSource = myDataSet.Tables[0].DefaultView;
            foreach (DataRow dr in dra)
            {
                XmlDocument doc = new XmlDocument();
            }/* End of connecting to database and filling the datagrid*/
}

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            planOfCare POCPage = new planOfCare();
            this.NavigationService.Navigate(POCPage);
}

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            caseMngHomeVisitReport CMHVRPage = new caseMngHomeVisitReport();
            this.NavigationService.Navigate(CMHVRPage);
        }

        private void MenuItemHVF(object sender, RoutedEventArgs e)
        {
            caseMngHomeVisitReport CMHVRPage = new caseMngHomeVisitReport();
            this.NavigationService.Navigate(CMHVRPage);
        }
        private void MenuItemPOC(object sender, RoutedEventArgs e)
        {
            planOfCare POCPage = new planOfCare();
            this.NavigationService.Navigate(POCPage);
        }
    }
}
